<?php

/**
 * This is a drop-dead simple front contoller
 *
 */

class Bridge_FrontController
{	
	public static function execute($config)
	{
		// get the right controller based on input

		$module = "bridge"; if ( array_key_exists("module", $_GET) ) $module = $_GET["module"];
		$action = ""; if ( array_key_exists("action", $_GET) ) $action = $_GET["action"];
		
		// cleanit and check to see if the controller exists
		
		$module = preg_replace("/\/|\./", "", $module);
		$controller = strtoupper( substr( $module, 0, 1 ) ) . substr( $module, 1 );
		$controller_class = $controller . "Controller";
		
		if ( file_exists("controllers/$controller.php") )
		{
			require_once("controllers/$controller.php");
			$conn = new $controller_class($config);
			$conn->execute();
		}
		else
		{
			throw new Exception("cannot find $controller_class");
		}
	}
}

abstract class Bridge_Abstract_Controller
{
	protected $config; // config file
	protected $transform; // xml transform
	protected $request; // http request
	protected $response; // response
	protected $view; // view

	public function __construct($config)
	{
		// utility classes
		
		require_once ("lib/Parser.php");
				
		$this->config = new SimpleXMLElement($config, null, true);
		$this->transform = new Bridge_Transform();
		$this->request = new Bridge_Request();
		$this->response = new Bridge_Response("bridge");
		$this->response->add($this->request->toXML());
	}
	
	abstract function execute();
}

?>